<% pages_obj ||= nil -%>
<% symbol2name_hash ||= nil -%>
<% title_icon ||= "user_comment" -%>
<% delete_categories ||= [] -%>

<%= %(<div id="#{id_name}">) %>

<div class="topix_title"><%= icon_tag(title_icon, :size=>"20x20") -%><span><%=h title_name %></span></div>

<div class="topix_body" id="<%= id_name -%>_body">

<% pages.each do |message| -%>

  <% entry_infos = get_entry_infos(message) -%>
  <% categories = message.category.scan(/\[[^\]]*\]/) -%>
  <% delete_categories.each {|categ| categories.delete(categ) } -%>

  <div style="border-bottom: 1px dotted silver; margin: 3px 0 1px 0; height: 16px; position: relative;">

    <div style="width: 80%;  white-space:nowrap; overflow:hidden; text-overflow:ellipsis; margin: 0;"><%= get_light_icon(message) -%>
      <%= hide_long_tags(categories, 3) %>
      <%= entry_link_to(message, {}, {:title => message.title + entry_infos}) -%> ... <span style="font-size:9px; background-color: #fff8ff;  vertical-align: middle; color: #aaaaaa;"><%= entry_infos -%></span></div>

    <div style="position: absolute; bottom:0px; right: 0; width: 15%; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; text-align: right; padding-left: 5px;font-size:10px;">
      <%= symbol2name_hash ? symbol_link_to(message.symbol, symbol2name_hash[message.symbol]) : user_link_to(message.user) -%></div>

  </div>

<% end -%>

<% if pages_obj -%>
<div style="text-align: right; font-size: 10px;"><span style="background-color: #fcffc5; padding: 0 2px 0 5px;">
<% if pages_obj.current.previous -%>
  <a class="first_link" id="<%= id_name -%>_first_link" href="#" >[最初へ]</a>
  <a class="back_link" id="<%= id_name -%>_back_link" href="#" >[前へ]</a>
<% end -%>
<%= %(全#{pages_obj.item_count}件（#{pages_obj.current.number}/#{pages_obj.length}ページ）) %>
<% if pages_obj.current.next -%>
  <a class="next_link" id="<%= id_name -%>_next_link" href="#" >[次へ]</a>
  <a class="last_link" id="<%= id_name -%>_last_link" href="#" >[最後へ]</a>
<% end -%>
<%= link_to('[ぜんぶ見る]', :controller => 'mypage', :action => "index", :list_type => id_name) -%>
</span></div>

<% end %>

</div><!-- topix_body -->

</div>
<script type="text/javascript">
<%# TODO この部分テンプレートが読み込まれる度に以下のjavascriptも読み込まれるがうまく分離できるのではないか？ %>
$j(function(){
    var id_name = '<%= id_name -%>';
    var loadEntries = function(page){
        $j.ajax({
            url: '<%= url_for(:controller => 'mypage', :action => 'load_entries') -%>',
            data: { page : page, page_name : 'list_block', target : id_name },
            complete: function(request) {
                $j('#' + id_name)
                .html(request.responseText).appendClickForToggleTag();
                $j('#' + id_name + '_body')
                .highlight();
                fnLoadPngs();
            }
        });
    };

    // 最初へ,前へ,次へ,最後へリンククリック時のajaxアクション
    $j('#' + id_name + '_first_link')
    .click(function() {
        loadEntries('1');
        return false;
    });
<% if pages_obj %>
    $j('#' + id_name + '_back_link')
    .click(function() {
        loadEntries('<%= pages_obj.current.previous.to_i -%>');
        return false;
    });

    $j('#' + id_name + '_next_link')
    .click(function() {
        loadEntries('<%= pages_obj.current.next.to_i -%>');
        return false;
    });

    $j('#' + id_name + '_last_link')
    .click(function() {
        loadEntries('<%= pages_obj.last.to_i -%>');
        return false;
    });
<% end %>
});
</script>
